import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:new_yuqib_app/yqbNetwork/api_metholds.dart';
import 'package:new_yuqib_app/yqbView/loading_view.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebController extends GetxController{
  final int typeId;
  WebController(this.typeId);

  @override
  void onInit() {
    super.onInit();
    loadData();
  }

  var webView = WebViewController().obs;

  var loadingType = LoadingType.loading.obs;

  loadData(){
    ApiMethods.xieyi().then((value){
      webView.value
        ..setJavaScriptMode(JavaScriptMode.unrestricted)
        ..setBackgroundColor(Colors.white)
        ..setNavigationDelegate(
          NavigationDelegate(
            onProgress: (int progress) {
              // Update loading bar.
            },
            onPageStarted: (String url) {},
            onPageFinished: (String url) {
              loadingType.value = LoadingType.none;
            },
            onWebResourceError: (WebResourceError error) {},
            onNavigationRequest: (NavigationRequest request) {
              return NavigationDecision.navigate;
            },
          ),
        )
        ..loadRequest(Uri.parse(typeId==0?value.userAgreementUrl:value.privacyAgreementUrl));
    });
  }
}